<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link href="/ajax/libs/jquery-layout/jquery.layout-latest.css" th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link href="/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>

<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="main-content">
			<div class="box box-main">
				<div class="box-header">
					<div class="box-title">
						<i class="fa icon-grid"></i> 班级架构
					</div>
					<div class="box-tools pull-right">
						<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新机构"><i class="fa fa-refresh"></i></button>
					</div>
				</div>
				<div class="ui-layout-content">
					<div id="tree" class="ztree"></div>
				</div>
			</div>
		</div>
	</div>
    <div class="container-div ui-layout-center">
    	<div class="row">
    		<div class="col-sm-12 select-info">
				<form id="operlog-form">
					<input type="hidden" id="classNumber" name="classNumber">
					<input type="hidden" id="gradeNumber" name="remark">
					<div class="select-list gd">
						<ul>
							<li>
								异常状态：<select name="status" style="width: 100px;">
									<option value="">所有</option>
									<option value="0">正常出入</option>
									<option value="1">未入校</option>
									<option value="2">提前入校</option>
									<option value="3">迟到</option>
									<option value="4">提前出校</option>
									<option value="5">出校超时</option>
									<option value="6">未出校</option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search($('form').attr('id'))"><i class="fa fa-search"></i>&nbsp;搜索</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        <div class="col-sm-12 select-info order-table">
		        <table id="bootstrap-table" data-mobile-responsive="true">
		        </table>
	        </div>
	    </div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
    <script th:inline="javascript">
        var prefix = ctx + "module/abnormal"
        
        $(document).ready(function(){
			$('body').layout({ west__size: 185 });
			queryUserList();
			queryClassesTreeDaTa();
		});

        function queryUserList() {
            var options = {
                url: prefix + "/studentList",
                modalName: "进出异常记录",
                search: false,
		        showExport: false,
                columns: [{
		            checkbox: true
		        },
		        {
		            title: '序号',
		            field: '',
		            align: 'center',
		            formatter: function (value, row, index) {
		                var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
		                var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
		                return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
		            }
		        },
				{
					field : 'inOutDate', 
					align: 'center',
					title : '进出日期' 
				},
				{
					field : 'studentNumber',
					align: 'center',
					title : '学号' 
				},
				{
					field : 'studentName', 
					align: 'center',
					title : '姓名' 
				},
				{
					field : 'className', 
					align: 'center',
					title : '所在班级' 
				},
				{
					field : 'inTime', 
					align: 'center',
					title : '入校时间',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openImg(\'' + row.inOutDate + '\',\'' + row.inTime + '\',\'' + row.ic_number + '\')">'+value+'</a>';
					}
				},
				{
					field : 'inStatus', 
					title : '状态',
					align: 'center',
					formatter: function(value, row, index) {
						if (value == '1') {
		                    return '<span class="badge badge-danger">未入校</span>';
		                } else if (value == '2') {
		                    return '<span class="badge badge-danger">提前入校</span>';
		                } else if (value == '3') {
		                    return '<span class="badge badge-warning">迟到</span>';
		                } else if (value == '4') {
		                    return '<span class="badge badge-warning">提前出校</span>';
		                } else if (value == '5') {
		                    return '<span class="badge badge-danger">出校超时</span>';
		                } else if (value == '6') {
		                    return '<span class="badge badge-danger">未出校</span>';
		                }else{
		                    return '<span class="badge badge-white">正常进出</span>';
		                }
		            }
				},
				{
					field : 'outTime', 
					align: 'center',
					title : '出校时间',
					formatter: function(value, row, index) {
						return '<a href="#" onclick="openImg(\'' + row.inOutDate + ',' + row.outTime + ',' + row.ic_number + '\')">'+value+'</a>';
					}
				},
				{
					field : 'outStatus', 
					title : '状态',
					align: 'center',
					formatter: function(value, row, index) {
						if (value == '1') {
		                    return '<span class="badge badge-danger">未入校</span>';
		                } else if (value == '2') {
		                    return '<span class="badge badge-danger">提前入校</span>';
		                } else if (value == '3') {
		                    return '<span class="badge badge-warning">迟到</span>';
		                } else if (value == '4') {
		                    return '<span class="badge badge-warning">提前出校</span>';
		                } else if (value == '5') {
		                    return '<span class="badge badge-danger">出校超时</span>';
		                } else if (value == '6') {
		                    return '<span class="badge badge-danger">未出校</span>';
		                }else{
		                    return '<span class="badge badge-white">正常进出</span>';
		                }
		            }
				}]
            };
            $.table.init(options);
        }
        
        function queryClassesTreeDaTa()
		{
			// 树结构初始化加载
			var setting = {view:{selectedMulti:false},data:{key:{title:"title"},simpleData:{enable:true}},
				callback:{onClick:function(event, treeId, treeNode){
					tree.expandNode(treeNode);
					if(treeNode.level == "1"){
						$("#gradeNumber").val(treeNode.id);
						$("#classNumber").val("");
					}else if(treeNode.level == "2"){
						$("#gradeNumber").val("");
						$("#classNumber").val(treeNode.id);
					}					
					$.table.search($('form').attr('id'));
				}}
			}, tree, loadTree = function(){
				$.get(ctx + "module/classes/treeData", function(data) {
				    tree = $.fn.zTree.init($("#tree"), setting, data); //.expandAll(true);
				    // 展开第一级节点
				    var nodes = tree.getNodesByParam("level", 0);
				    for (var i = 0; i < nodes.length; i++) {
				        tree.expandNode(nodes[i], true, false, false);
				    }
				    // 展开第二级节点
				    nodes = tree.getNodesByParam("level", 1);
				    for (var i = 0; i < nodes.length; i++) {
				        tree.expandNode(nodes[i], true, false, false);
				    }
				}, null, null, "正在加载，请稍后...");
			};loadTree();
			
			$('#btnExpand').click(function() {
				tree.expandAll(true);
			    $(this).hide();
			    $('#btnCollapse').show();
			});
			$('#btnCollapse').click(function() {
				tree.expandAll(false);
			    $(this).hide();
			    $('#btnExpand').show();
			});
			$('#btnRefresh').click(function() {
			    loadTree();
			});
		}
        
        function getAppellation(id){
        	var s = "";
        	switch (id){
        		case "1":
        			s = "父亲";
        			break;
        		case "2":
        			s = "母亲";
        			break;
        		case "3":
        			s = "爷爷";
        			break;
        		case "9":
        			s = "家长";
        			break;
        		default:
        			s = id;
        	}
        	return s;
        }
        
        function openImg(inOutDate,inOutTime,icNumber){
        	inOutDate = inOutDate.replace(/-/g,"").replace(" ","");
        	inOutTime = inOutTime.replace(/:/g,"").replace(" ","");
        	layer.open({
       	      type: 2,
      	   	  title: "学生进出图片", 
       	      shadeClose: true,
       	      shade: true,
       	      maxmin: true, //开启最大化最小化按钮
       	      area: ['800px', '400px'],
       	      content: 'http://urpattendance.test.upcdn.net/223287114'+inOutDate+inOutTime+icNumber+'.jpg'
       	    });
        }
    </script>
</body>
</html>